package com.shangguan.spring.controller;

import com.shangguan.spring.beans.User;
import com.shangguan.spring.service.UserService;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.List;

/**
 * @ClassName: MemeberController
 * @Description:
 * @Author: 一尘
 * @Date: 2020 年 05 月 20 10:34
 * @Version 1.0
 */
@Controller
@RequestMapping("/member")
public class MemeberController {
    @Autowired
    UserService userService;
    @GetMapping("/list")
    public String list(Model model){
       List<User> list = userService.selectUsers();
       if(list.size()>0){
           model.addAttribute("list",list);
           model.addAttribute("count",list.size());
       }else {
            model.addAttribute("message","查询数据异常!");
        }
        return "member-list";
    }


    @ApiOperation(tags = "用户编辑",value = "用户编辑")
    @ApiImplicitParam(name = "userid",value = "用户编号",defaultValue = "",dataType ="string",required = true)
    @GetMapping("/edit/{userid}")
    public  String edit(@PathVariable("userid") int userid,Model model){
        User  user= userService.selectByPrimaryKey(userid);
        model.addAttribute("user",user);
        return "member-edit";
    }
}
